[15/07/09 22:53:23] Ваати: Here's the difference between cookies and sessions
[15/07/09 22:54:12] Ваати: Cookies - Saves information on the user's computer
Session - Saves information on the server
[15/07/09 22:54:36] Mr. Boyd: so a session is essentially a server-side cookie then?
[15/07/09 22:54:57] Ваати: Pratically, here's how it works. I'll try to explain
[15/07/09 22:55:00] Mr. Boyd: but a secure one which will be auto-deleted on timeout
[15/07/09 22:55:38] Ваати: By default, Sessions last for a set amount of time, yes timeout. If it isn't accessed it'll be deleted and all the data in it.
[15/07/09 22:56:19] Ваати: A session file itself, is stored on the server and cannot be edited or downloaded in any way, it's impossible.
[15/07/09 22:56:43] Ваати: The only way to access them or read them is thorugh an interpretive language, like PHP
[15/07/09 22:57:06] Ваати: That or, if you own the server or set the session data to a known folder you can download one
[15/07/09 22:57:25] Ваати: Alright, as for how they're set and work
[15/07/09 22:57:51] Ваати: You start a session normally in PHP with session_start();
[15/07/09 22:58:26] Ваати: This will do two things, creates a session file on the server, empty. The filename itself is in a random md5.
[15/07/09 22:58:49] Ваати: It will then also set a cookie, the cookie is also md5'd
[15/07/09 22:59:33] Ваати: When the browser is on that page, as long as the md5 is matched to some alogorithm to match the md5 in the session folder on the server, it will only access those session's variables
[15/07/09 23:00:13] Ваати: That's why it's very secure, you'd have to be VERY persistant to find a matching md5 to access a session file on the server. Almost brute forcing
[15/07/09 23:00:38] Ваати: However there is another way to hack/access the session, but I'll explain that later
[15/07/09 23:01:10] Mr. Boyd: and with any luck the session file would time out before the brute forcer would get anywhere near the write combination
[15/07/09 23:01:22] Ваати: After session_start(); you can start putting in things right away like a name/username
[15/07/09 23:01:42] Ваати: Using $_SESSION['variablename'] = '';
[15/07/09 23:01:46] Ваати: Very very easy
[15/07/09 23:02:06] Mr. Boyd: no needing to refresh and write a cookie before any data is echoed?
[15/07/09 23:02:16] Mr. Boyd: oh wait,
[15/07/09 23:02:21] Ваати: You still have to because there's one cookie
[15/07/09 23:02:28] Mr. Boyd: no for log ins it'd be same,
[15/07/09 23:02:29] Ваати: the one that identifies which session to access
[15/07/09 23:02:46] Mr. Boyd: but that's still an advantage!
[15/07/09 23:03:12] Ваати: Destroying the session is very easy too
[15/07/09 23:03:32] Ваати: Like when you logout
[15/07/09 23:03:33] Mr. Boyd: but I can see the advantage of cookies for regular users, keeping everything as sessions would be rather intensive on the server
[15/07/09 23:03:51] Ваати: Actually, it's not
[15/07/09 23:03:58] Mr. Boyd: really?
[15/07/09 23:04:00] Ваати: That's the entire reason sessions exist!
[15/07/09 23:04:18] Mr. Boyd: despite having a session file for each one?
[15/07/09 23:04:21] Ваати: It's no different than reading echo 'somestring';
[15/07/09 23:04:55] Ваати: But to logout, all you need to do is session_destroy();
[15/07/09 23:05:12] Mr. Boyd: ok, one question,
[15/07/09 23:05:20] Ваати: If you simply want to erase all the session data in the file use: session_unset();
[15/07/09 23:05:25] Mr. Boyd: does that have to be before any header info is sent out?
[15/07/09 23:05:31] Ваати: Yes
[15/07/09 23:05:31] Mr. Boyd: like with cookies?
[15/07/09 23:05:35] Mr. Boyd: ah,
[15/07/09 23:05:38] Ваати: It's crucial, before any html is generated
[15/07/09 23:05:57] Ваати: Now then, on to security
[15/07/09 23:06:15] Ваати: Other than brute force, there's another very easy way to steal a session
[15/07/09 23:06:25] Ваати: Just steal the cookie identifying the session
[15/07/09 23:06:56] Ваати: Or in some cases, use a blank session and hope some vulnerability is opened using a blank one
[15/07/09 23:07:09] Ваати: The second one is easy to avoid
[15/07/09 23:07:22] Ваати: Make sure each session has an identifier
[15/07/09 23:07:29] Ваати: Or a pre-set variable no matter what
[15/07/09 23:07:56] Ваати: Ie. $_SESSION['notblank'] = 'filler';
[15/07/09 23:08:15] Ваати: then a simple script to test if a session has any data
[15/07/09 23:08:34] Mr. Boyd: hang on,
[15/07/09 23:08:59] Ваати: ie.

if (!$_SESSION['notblank']) { ...
[15/07/09 23:09:24] Ваати: It doesn't matter, the variable could be anything but there MUST be session data in the session for it to be valid
[15/07/09 23:09:35] Ваати: If not, then we use the magical security function sessions have
[15/07/09 23:09:42] Ваати: session_regenerate_id(true);
[15/07/09 23:09:50] Ваати: You can guess what that does
[15/07/09 23:09:56] Mr. Boyd: ok, one moment,
[15/07/09 23:10:00] Ваати: Alright
[15/07/09 23:10:13] Mr. Boyd: I'm lost on the point of creating a filler session,
[15/07/09 23:10:47] Ваати: The filler session is just there incase of you making an error
[15/07/09 23:10:47] Mr. Boyd: regenerate ID I can guess what it does, assigns a new MD5 hash ID to existing data
[15/07/09 23:11:34] Ваати: like you mess up on authing a page and the fact that the person has no data in his session he can access things because you didn't check for it
[15/07/09 23:12:00] Mr. Boyd: ah, right
[15/07/09 23:12:13] Mr. Boyd: like on VL at the moment,
[15/07/09 23:12:21] Ваати: So if you can check if a person has no data in a filler variable, you can issue them a NEW session with the filler attached
[15/07/09 23:12:21] Mr. Boyd: the cookie script is screwed,
[15/07/09 23:13:32] Mr. Boyd: logins will direct to a blank page because the page is meant to refresh but I stripped out the code just now and going to the map page without a cookie displays a map and user controls, but it's a map of error messages
[15/07/09 23:14:09] Mr. Boyd: I haven't written the code to redirect to the login page in case of no cookie yet
[15/07/09 23:14:33] Mr. Boyd: I've been rather distracted by trying to get this whole radio thing sorted with active DJs
[15/07/09 23:16:16] Ваати: And the question is....?
[15/07/09 23:16:22] ВИРУС: Dicks
[15/07/09 23:16:22] Animu: WHERE DA HOOD AT?
[15/07/09 23:16:32] ВИРУС: bing bing bing bing
[15/07/09 23:16:39] Ваати: hold on bros
[15/07/09 23:16:43] ВИРУС: AND OUR SURVEY SAYS
[15/07/09 23:16:42] Ваати: talking to smashed
[15/07/09 23:16:57] Animu: das coo my headset is completely fucked anywai
[15/07/09 23:17:07] Ваати: WHEN YOU GETTING DAT NEW ONE
[15/07/09 23:17:09] Animu: not to mention my sisters like "OH NO I'M TOO PO' TO BUY YOU A NEW ONE"
[15/07/09 23:17:12] Animu: ^%^^^
[15/07/09 23:17:15] Ваати: HAHABULLSHIT
[15/07/09 23:17:18] Mr. Boyd: the question was actaully, why create a filler session and not just have something which checks if a session is started?
[15/07/09 23:17:19] Animu: HAHAFUCK.
[15/07/09 23:17:32] Animu: More at 11.
[15/07/09 23:18:24] Mr. Boyd: so if a session is meant to be active but it's not, ask the user to log in
[15/07/09 23:18:37] Ваати: Smashed, it's more of a consistancy check so users won't CREATE their own session
[15/07/09 23:18:49] Mr. Boyd: ah, ok
[15/07/09 23:18:50] Ваати: To put simply, it as if there was a concert to a big show
[15/07/09 23:19:03] Ваати: Someone figured out how to forge their ticket
[15/07/09 23:19:06] Mr. Boyd: so you OVERWRITE any existing session
[15/07/09 23:19:20] Ваати: And this is the method to see if that ticket was issued by us
[15/07/09 23:19:42] Mr. Boyd: gotcha,
[15/07/09 23:19:45] Mr. Boyd: now I get it
[15/07/09 23:19:58] Ваати: And exactly, if the session is not legitamately created. Then create it and issue it a identifier
[15/07/09 23:20:12] Ваати: The code I use is very simple for that, I use...
[15/07/09 23:20:25] Ваати: if (!$_SESSION['UID']) {
 session_regenerate_id(true);
 $_SESSION['UID'] = md5(rand(0,1000).time());
}
[15/07/09 23:21:02] Ваати: Because even though a user can create their own session ID, they cannot create the data in that session, only the server can through php
[15/07/09 23:22:05] Ваати: Alright, on to the next woe of sessions, the most evil of all. Session hijacking.
[15/07/09 23:22:22] Ваати: Lets say the attacker sets up a phising site to STEAL the cookie id
[15/07/09 23:22:51] Ваати: Now the attcker has the id and all he needs to do is plug the cookie in his browser and jump right into the site and be logged in
[15/07/09 23:23:04] Ваати: Of course, if it hasn't timed out by then
[15/07/09 23:23:24] Ваати: There are many ways thankfully, to avert this
[15/07/09 23:23:52] Ваати: One way, is to use the user's browser information to identify the session
[15/07/09 23:24:01] Ваати: Kind of like a fingerprint if you will
[15/07/09 23:24:35] Ваати: To do that, all you need to do is
[15/07/09 23:24:53] Ваати: $str = md5($_SERVER['HTTP_USER_AGENT']);
$_SESSION['BID'] = $str;
[15/07/09 23:25:15] Mr. Boyd: ah,
[15/07/09 23:25:19] Ваати: Then store the $str, the browser information itself somewhere
[15/07/09 23:25:24] Ваати: Like the database
[15/07/09 23:25:27] Mr. Boyd: which would tie it into their browse
[15/07/09 23:25:33] Mr. Boyd: *browser
[15/07/09 23:25:59] Mr. Boyd: but would also time out the session if the legit user switches into a different browser
[15/07/09 23:26:10] Ваати: Then everytime a page is accessed, get the user's browser information again
[15/07/09 23:26:46] Ваати: Yes it would, but that's a minor inconvinience for a tradeoff in HUGE security
[15/07/09 23:26:56] Mr. Boyd: undeniably
[15/07/09 23:27:07] Ваати: As a webcoder, you must live by one of the most crucial laws and that is to trust NO ONE
[15/07/09 23:27:15] Ваати: Not even your own legitamite users
[15/07/09 23:27:29] ВИРУС: WHAT THE FUUU
[15/07/09 23:27:38] Ваати: A lot of simple hacks can be done by simply being able to use two browsers logged in at once
[15/07/09 23:27:53] Ваати: So if you restrict the session to only one fingerprint, you've won
[15/07/09 23:28:01] Mr. Boyd: I know, that's why with the radio, despite giving out the radio admin password, I have direct access to the server it's hosted
[15/07/09 23:28:07] Ваати: And that ends all the anti-hacks for sessions
[15/07/09 23:28:22] Ваати: Save for you getting keylogged but if you have common sense you won't
[15/07/09 23:28:31] Mr. Boyd: and even my friend who owns the server has the ability to remotely kill and block access to anyone but himself
[15/07/09 23:28:46] Mr. Boyd: agreed,
[15/07/09 23:28:47] Ваати: And this is why sessions are infinantly better than cookies, ah but I forgot one thing
[15/07/09 23:29:17] Ваати: For added security, everytime you enter a heavy security page/feature
[15/07/09 23:29:21] Mr. Boyd: ok, mind if I save this chat log in a txt file?
[15/07/09 23:29:30] Ваати: ALWAYS regenerate the session id with session_regenerate_id(true);
[15/07/09 23:29:56] Ваати: This will keep all the data in the session and issue both a new id and it's matching cookie to the browser
[15/07/09 23:29:57] Mr. Boyd: each time the page is accessed or the site is accessed?
[15/07/09 23:30:05] Ваати: the "true" deletes the old session
[15/07/09 23:30:12] Ваати: everytime session_regenerate_id(true); is run
[15/07/09 23:30:21] Ваати: Now you may think, let's place session_regenerate_id(true); on every page
[15/07/09 23:30:29] Mr. Boyd: no,
[15/07/09 23:30:46] Ваати: Well you can, but session_regenerate_id() is a bit of a resource hog
[15/07/09 23:30:54] Mr. Boyd: that's why I asked, lol, I can imagine that being
[15/07/09 23:31:00] Ваати: As it's actively deleting/copying session data over
[15/07/09 23:31:06] Mr. Boyd: well, you beat me to it (damn slow typing speed)
[15/07/09 23:31:30] Ваати: Plus an error may happen (blackout and datastream interrupt as rare as they are) and you may screw that session over
[15/07/09 23:31:37] Ваати: so only start session where needed
[15/07/09 23:31:49] Ваати: Like the admin CP or everytime someone posts/changes something
[15/07/09 23:31:57] Mr. Boyd: and only regen it on important pages?
[15/07/09 23:32:02] Ваати: But for browsing and viewing things you should be safe
[15/07/09 23:32:05] Ваати: Exactly
[15/07/09 23:32:14] Ваати: Be smart with it, sessions are powerful things
[15/07/09 23:32:28] Mr. Boyd: right, cheers, I hope I've been a good student.